import sys

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    def __eq__(self, point):
        return self.x==point.x and self.y==point.y
    def __ne__(self, point):
        return not self.__eq__(point)
    def __hash__(self):
        return (self.x+self.y)*(self.x+self.y+1)//2 + self.y
    def __repr__(self):
        return "[{},{}]".format(self.x, self.y)

class Solution(object):
    def isRectangleCover(self, rectangles):
        """
        :type rectangles: List[List[int]]
        :rtype: bool
        """
        pDict = {}

        def add(l, b, r, t):
            point = Point(l, b)
            if point not in pDict: pDict[point]=0
            pDict[point]+=1
            point = Point(r, t)
            if point not in pDict: pDict[point]=0
            pDict[point]+=1
            point = Point(l, t)
            if point not in pDict: pDict[point]=0
            pDict[point]+=1
            point = Point(r, b)
            if point not in pDict: pDict[point]=0
            pDict[point]+=1
            
        area = 0
        left, bottom, right, top = sys.maxsize, sys.maxsize, -sys.maxsize, -sys.maxsize 
        for l, b, r, t in rectangles:
            left = min(left, l)
            bottom = min(bottom, b)
            right = max(right, r)
            top = max(top, t)
            
            area +=(r-l)*(t-b)

            add(l,b,r,t)
        add(left, bottom, right, top)
        return area==(right-left)*(top-bottom) and all(map(lambda x:x%2==0, pDict.values()))

print(Solution().isRectangleCover( [
  [1,1,3,3],
  [3,1,4,2],
  [3,2,4,4],
  [1,3,2,4],
  [2,3,3,4]
]))